<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color: black;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <div id="code"></div>
    <script>
        // 设置画布
        let canvas = document.createElement('canvas')
        let ctx = canvas.getContext('2d')

        // 设置画布宽高
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        // 将canvas添加到页面
        document.getElementById('code').appendChild(canvas)

        // 设置字符集
        let code = 'UODAHOAHDJAKDJAWIOJL472340Q7491'
        code = code.split('')

        // 设置字体大小
        let fontSize = 16;
        // 设置间距
        let space = canvas.width / fontSize

        // 设置初始速度
        let speed = []
        for (let i = 0; i < space; i++) {
            speed[i] = Math.floor(Math.random() * canvas.height)
        }
        function draw() {
            // 绘制背景
            ctx.fillStyle = 'rgba(0,0,0,0.05)'
            ctx.fillRect(0, 0, canvas.width, canvas.height)
            // 绘制字体
            ctx.fillStyle = '#0F0'
            ctx.font = fontSize + 'px arial'
            for (let i = 0; i < speed.length; i++) {
                // 随机选择一个字符
                let text = code[Math.floor(Math.random() * code.length)]
                ctx.fillText(text, i * fontSize, speed[i] * fontSize)
                // 设置字符超出canvas，则重置字符下落速度
                if (speed[i] * fontSize > canvas.height && Math.random() > 0.975) {
                    speed[i] = 0
                }
                speed[i]++
            }
        }
        // 设置每隔三十毫秒执行一次
        setInterval(draw, 30)
    </script>
</body>

</html>